public class Solution1601 {

    int max=0;

    public int maximumRequests(int n, int[][] requests) {
        boolean[] visit=new boolean[requests.length];
        dfs(0,requests.length,visit,requests,n);
        return max;
    }

    private void dfs(int k, int n, boolean[] visit, int[][] requests,int m) {
        if (k==n){
            check(visit,requests,m);
            return;
        }
        dfs(k+1,n,visit,requests,m);
        visit[k]=true;
        dfs(k+1,n,visit,requests,m);
        visit[k]=false;
    }

    private void check(boolean[] visit, int[][] requests, int n) {
        int count=0;
        int[] f=new int[n];
        for (int i=0;i<requests.length;i++){
            if (visit[i]){
                count++;
                f[requests[i][0]]--;
                f[requests[i][1]]++;
            }
        }
        for (int i = 0; i < n; i++) {
            if (f[i]!=0){
                return;
            }
        }
        max=Math.max(max,count);
    }

    public static void main(String[] args) {
        System.out.println(new Solution1601().maximumRequests(5,new int[][]{{0,1},{1,0},{0,1},{1,2},{2,0},{3,4}}));
    }
}
